<%@ page language="java" import="java.util.*,java.sql.*,java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%@include file="/resources/include.jsp" %>
<%@include file="DBHelper.jsp" %>
<%!
    public String ms_Action;
    public String ms_UserName;
    public String ms_TemplateID;
    public String ms_FileType;
    public String ms_RecordID;
    public String ms_Author;
    public String ms_FileDate;
    public String ms_Subject;
    public String ms_WebUrl;
%>
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    ms_Action = request.getParameter("action");
    if(ms_Action == null){
        ms_Action = "new";
    }
    // new:新建文档;read:阅读;norevision:修改无痕迹;yesrevision:修改有痕迹;comment:领导手写圈批;verify:核稿;embed:一键套红;seal:签章
    // MS:doc,xls,ppt|WPS:wps,et,dps
    if ("new".equals(ms_Action)){
        //新建文档
        ms_FileType = "doc";
        ms_TemplateID = "";
        ms_UserName = "user";

        ms_RecordID = getDateTimeFormat();
        ms_Subject = "请输入主题";
        ms_Author = ms_UserName;
        ms_FileDate = GetDateTime();
    } else {
        ms_RecordID = request.getParameter("d_recordid");
    }
    
    String contextUrl= request.getContextPath();
    ms_WebUrl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextUrl+"/";
    ms_WebUrl +="resources/JSLIB/plugins/eweboffice/eWebOffice/eWebOfficeAction.jsp";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>" />
<title>编辑文档</title>
<link rel="stylesheet" href="resources/JSLIB/dojo/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="resources/JSLIB/plugins/eweboffice/css/eweboffice.css" />
<link rel="stylesheet" href="resources/JSLIB/plugins/jquery/jqGrid/css/ui.jqgrid.css" />
<link rel="stylesheet" href="resources/JSLIB/plugins/jquery/jqGrid/css/ui.multiselect.css" />
<link rel="stylesheet" href="resources/JSLIB/plugins/jquery/jqGrid/css/jquery-ui-custom.css" />
<link rel="stylesheet" href="resources/JSLIB/plugins/jquery/zTree/css/zTreeStyle/zTreeStyle.css" />
<link rel="stylesheet" type="text/css" href="resources/CSS/style.css" />
<style type="text/css">
label.error { color: red; }
strong { color: red; float: right;}
</style>
<!--引用eWebOffice公用脚本-->
<script type="text/javascript" src="resources/JSLIB/plugins/eweboffice/eWebOffice/eWebOffice.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/socket.io/socket.io.js"></script>
<script type="text/javascript" src="resources/JSLIB/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/jqGrid/plugins/jquery-ui-custom.min.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/jqGrid/plugins/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/jqGrid/plugins/jquery.tablednd.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/jqGrid/plugins/ui.multiselect.js"></script>
<script type="text/javascript" src="resources/JSLIB/plugins/jquery/zTree/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="resources/JSLIB/dojo/dojo/dojo.js" data-dojo-config="parseOnLoad:true, async:true"></script>
<script type="text/javascript" for="eWebOffice1" event="OnInit()">
    //控件初始化事件
    //标题栏、快捷工具栏、边框等界面相关设置可以在此事件中作，使得界面上不会有转变过程显现
    //如：隐藏快捷工具栏。当访问此网页时，如在OnLoad中设，则会先显示出工具栏，再看到工具栏没了。如在OnInit中设，直接打开就看不到。没有这个变化过程。
    eWebOfficeJS.SetWorkModeOnInit("eWebOffice1", "<%=ms_Action%>");
    eWebOffice1.TitleVisible=false;
</script>

<script type="text/javascript" for="eWebOffice1" event="OnDocumentAfterOpen()">
    //文档打开后触发此事件
    //在此事件中设置初始Office菜单、工具栏、痕迹、保护等。
    eWebOfficeJS.SetWorkModeOnOpen("eWebOffice1", "<%=ms_Action%>");
</script>

<script type="text/javascript" for="eWebOffice1" event="OnLoad()">
    eWebOffice1.WebUrl = "<%=ms_WebUrl%>";
    eWebOffice1.RecordID = "<%=ms_RecordID%>";
    eWebOffice1.TemplateID = "<%=ms_TemplateID%>";
    eWebOffice1.UserName = "<%=ms_UserName%>";
    eWebOffice1.FileType = "<%=ms_FileType%>";
    <% if( "new".equals(ms_Action)){%>
    eWebOffice1.WebNew();
    <% }else{ %>
    eWebOffice1.WebOpen();
    <% } %>
</script>

<script type="text/javascript" for="eWebOffice1" event="OnCustomButtonClick(s_Key, s_Value)">
    //s_Key: 为自定义按钮关键字，可以随便定义，不要与系统自带冲突即可，为了区别，快捷工具栏上的按钮定义为"QB_"开头，Office文件菜单下的按钮定义为"File_"开头。
    switch(s_Key){
    case "QB_ViewThumbnails":
        eWebOffice1.WebObject.Application.ActiveWindow.Thumbnails = true;
        break;
    case "QB_ViewDocumentMap":
        eWebOffice1.WebObject.Application.ActiveWindow.DocumentMap = true;
        break;
    case "QB_ViewPage":
        eWebOffice1.WebObject.Application.ActiveWindow.Thumbnails = false;
        eWebOffice1.WebObject.Application.ActiveWindow.DocumentMap = false;
        break;
    case "QB_Print":
        eWebOffice1.PrintDialog();
        break;
    case "QB_WebSave":
        eWebOffice1.WebSave();
        break;
    case "QB_EmbedTemplate":
        var o_Arg = new Object();            //准备传递到模式窗口的对象
        o_Arg.TemplateID = "";               //初始化对象的模板属性
        //弹出模板列表的模式窗体（url， 传递到模式窗口的参数，模式窗口的样式属性）
        window.showModalDialog("template_select.jsp", o_Arg, "dialogHeight:130px; dialogWidth:360px;center:yes;scroll:no;status:no;");
        if (o_Arg.TemplateID != ""){
            eWebOffice1.TemplateID = o_Arg.TemplateID;        //将模式窗口取得的TemplateID赋值给控件中的TemplateID属性
            eWebOffice1.WebEmbedTemplate();                    //嵌入模板
        }
        break;
    case "QB_OpenSeal":
        eWebOffice1.WebOpenSeal();
        break;
    case "QB_VerifySeal":
        eWebOffice1.WebVerifySeal();
        break;
    }
</script>

<script type="text/javascript">
var username = '<shiro:principal  property="username"/>';
function DoCheckSubmit(){
    //当保存为草稿的时候验证印刷份数是否为数字
    var reg = new RegExp("^[0-9]{1,3}$");
    if(!reg.test($("#ysfs").val())&&$("#ysfs").val()!=""){
        alert("印刷份数必须为数字且必须小于三位");
        return false;
    }
    if($("#ysfs").val()==""){
        $("#ysfs").val(0);
    }
    try{
        return eWebOffice1.WebSave();
    }catch(e){
        alert("请选安装eWebOffice控件，再操作！");
        return false;
    }
}
function doProcess() {
    if($("#myform").valid()){
        if($.trim($("#clrxm").val())== ""){
            alert("核搞人不能为空!");
            $("#clrxm").focus();
            return false;
        }
        $("#clzt").val("1");
        $("#myform").submit();
        socket.send($("#clrxm").val());
    }
}
$(document).ready(function(){
    $(document).keydown(function(e) {
        var doPrevent;
        if (e.keyCode == 8) {
            var d = e.srcElement || e.target;
            if (d.tagName.toUpperCase() == 'INPUT' || d.tagName.toUpperCase() == 'TEXTAREA') {
                doPrevent = d.readOnly || d.disabled;
            } else {
                doPrevent = true;
            }
        } else {
            doPrevent = false;
        }
        if (doPrevent) {
            e.preventDefault();
        }
    });
    $(":button").bind("click",function(evt){
        evt.preventDefault();
    });
    $("#myform").validate({
        onsubmit: false ,
        rules : {
            ysfs : {
              required: true,
              digits: true,
              maxlength: 3
            },
            gwbt : {
              required: true
            },
            ztc : {
              required: true
            },
            zsdwmc : {
              required: true
            },
            csdwmc : {
              required: true
            },
            ngr : {
              required: true
            },
            ngdwmc : {
              required: true
            }
        },
        messages : {
            ysfs : {
                required: '必填值',
                digits: '只能是数字',
                maxlength: '长度不能大于3'
            },
            gwbt : {
                required: '必填值'
            },
            ztc : {
                required: '必填值'
            },
            zsdwmc : {
                required: '必填值'
            },
            csdwmc : {
                required: '必填值'
            },
            ngr : {
                required: '必填值'
            },
            ngdwmc : {
                required: '必填值'
            }
        }
    });
});
</script>

</head>
<body  class="claro">
<div id="bdy">
<form id="myform" method="post" action="<%=contextUrl %>/document/insert" onsubmit="return DoCheckSubmit()">
<input type="hidden" name="d_recordid" id="d_recordid" value="<%=ms_RecordID%>" />
<input type="hidden" name="d_filetype" id="d_filetype"  value="<%=ms_FileType%>" />
<input type="hidden" name="gwtype" id="gwtype" value="0"/>
<input type="hidden" name="d_subject" id="d_subject" />
<input type="hidden" name="d_author" id="d_author" />
<input type="hidden" name="cllb" id="cllb" value="101"/>
<input type="hidden" name="clzt" id="clzt" value="0"/>
<table class="edit">
<tr>
  <th colspan="6" align="center"><h2>发文登记(拟稿)</h2><br/></th>
</tr>
<tr>
  <td align="center">发文编号</td>
  <td><input class="txt" type="text" name="gwbh" id="gwbh" size="30" /></td>
  <td align="center">公文缓急</td>
  <td>
  <select name="jjcd" id="jjcd">
    <option value="0">普通</option>
    <option value="1">重要</option>
    <option value="2">紧急</option>
    <option value="3">加急</option>
  </select>
  </td>
  <td align="center">印刷份数<strong>*</strong></td>
  <td><input class="txt" type="text" name="ysfs" id="ysfs" size="15" value=0 /></td>
</tr>
<tr>
  <td align="center">发文类别</td>
  <td>
  <select name="gwlb" id="gwlb">
    <option value="0">行政</option>
    <option value="1">人事</option>
    <option value="2">财政</option>
    <option value="3">党委</option>
  </select>
  </td>
  <td align="center">文件密级</td>
  <td colspan="3">
  <select name="gwmj" id="gwmj">
    <option value="0">普密</option>
    <option value="1">机密</option>
    <option value="2">绝密</option>
  </select>
  </td>
</tr>
<tr>
  <td align="center">发文标题<strong>*</strong></td>
  <td colspan="5"><input class="txt" type="text" name="gwbt" id="gwbt" size="120" /></td>
</tr>
<tr>
  <td align="center">主题词<strong>*</strong></td>
  <td colspan="5"><input class="txt" type="text" name="ztc" id="ztc" size="120" /></td>
</tr>
<tr>
  <td align="center">主送单位<strong>*</strong></td>
  <td colspan="5"><input class="txt" type="text" name="zsdwmc" id="zsdwmc" size="120" /></td>
</tr>
<tr>
  <td align="center">抄送单位<strong>*</strong></td>
  <td colspan="5"><input class="txt" type="text" name="csdwmc" id="csdwmc" size="120" /></td>
</tr>
<tr>
  <td align="center">拟稿人<strong>*</strong></td>
  <td><input class="txt" type="text" name="ngr" id="ngr" size="30" readonly="readonly" value="<shiro:principal  property="username"/>"/></td>
  <td align="center">拟稿单位<strong>*</strong></td>
  <td colspan="3"><input class="txt" type="text" name="ngdwmc" id="ngdwmc" size="30" /></td>
</tr>
<tr>
  <td align="center">发文附件</td>
  <td colspan="5">
      <input id="uploadWighet" name="fj" data-dojo-type="dijit/form/TextBox" data-dojo-props="readonly : true" style="width: 400px;" onclick="uploadComponet(this,'attachId');"/>
      <input id="attachId" name="fileid" type="hidden" >
  </td>
</tr>
<tr>
  <td align="center">核稿人</td>
  <td colspan="5">
        <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readonly : true" name="clrxm" id="clrxm"  cType="s" onclick="showUserTree(this,'clrid');"/>
        <input type="hidden" id="clrid" name=clrid />
  </td>
</tr>
<tr>
  <td colspan="6" align="center">
    <input type="submit" class="btn" value="保存草稿"/>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" class="btn" value="拟办报送" onclick="doProcess();"/>
    <br/><br/>
    <span class=red>注意：只有进行"保存文档"后，所做的操作才有效！</span>
  </td>
</tr>
</table>
</form>
<!--创建eWebOffice实例-->
<script type="text/javascript">
eWebOfficeJS.SetBasePath('<%=contextUrl%>/resources/JSLIB/plugins/eweboffice/eWebOffice/');
eWebOfficeJS.Create("eWebOffice1", "100%", "500px");
</script>
</div>
<div data-dojo-type="dijit/Dialog" data-dojo-id="attachModal">
    <div data-dojo-type="dojox/layout/ContentPane" data-dojo-id="attachUploadPane" data-dojo-props="refreshOnShow : true" style="width: 900px;height: 544px;margin: 0;padding: 0;"></div>
</div>
<script type="text/javascript">
var basePath = '<%=ms_WebUrl%>';
var socketport = '9999';//TODO: 根据不同的环境要做修改
var hostname = basePath.substring(0, basePath.lastIndexOf(':') + 1);
// Connect SocketIo Server
socket = io.connect(hostname + socketport, {
    'reconnection delay' : 2000,
    'force new connection' : true
});
</script>
<script type="text/javascript">
require([ "dojo/dom", "dijit/popup", "dojox/layout/ContentPane" ], function(dom, popup, ContentPane) {
    var userdropTreePane = new ContentPane({
        refreshOnShow : true,
        style : 'width: 165px;height:250px;background: #f0f6e4;border: solid 1px #85B5D9;',
        onMouseLeave : function() {
            popup.close(this);
        }
    });
    showUserTree = function(obj, realId) {
        var url = "sysuser/dropTree?dropId=" + obj.id + "&cType=" + obj.cType + "&keyId=" + realId;
        userdropTreePane.set("href", url);
        popup.open({
            parent : obj,
            popup : userdropTreePane,
            around : obj.domNode
        });
        userdropTreePane.startup();
    };
});
require([], function() {
    uploadComponet = function(obj, realId) {
        var url = "attachcatalog/page?dropId=" + obj.id + "&keyId=" + realId;
        attachUploadPane.set("href", url);
        attachModal.show();
    };
});
</script>
</body>
</html>